import 'package:app/common/app_theme.dart';
import 'package:app/pages/userinfo_module/userinfo_controller.dart';
import 'package:app/pages/userinfo_module/userinfo_updata_view.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

import '../../services/address.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'dart:io';
class UserInfoView extends GetView {




  UserInfoController controller = Get.put(UserInfoController());


  var list = ['','昵称','性别','地址','生日'];

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          onPressed: () {
            Get.back();
          },
          icon: Image.asset(
            'images/leftarr.png',
            width: 15,
            height: 15,
          ),
        ),
        title: Text('个人信息',style: appThemeData.textTheme.bodyText1!.copyWith(fontSize: 16),),
      ),
      body: GetBuilder<UserInfoController>(builder: (_){


        return ListView.builder(
          itemBuilder: (BuildContext context, int index) {

            return index==0? GestureDetector(
              child: Container(
                padding: EdgeInsets.only(left: 15,right: 15),
                alignment: Alignment.centerLeft,
                color: Colors.white,
                height: 80,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    // print(controller.listFilePaths);
                    Row(
                      children: [
                        controller.listFilePaths!.isNotEmpty?CircleAvatar(
                          // child: Image.file(File(controller.listFilePaths![0].path.toString())),
                          backgroundImage: FileImage(File(controller.listFilePaths![0].path.toString())),
                        ):
                            Container(
                              clipBehavior: Clip.antiAlias,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.all(Radius.circular(25))
                              ),
                              child:  CachedNetworkImage(
                                fit: BoxFit.cover,
                                width: 50,
                                height: 50,
                                imageUrl: "${Address.homeHost}${controller.model?.data?.image_128??'/web/image/128?field=&model=res.partner&id=3&t=bfe17191edf3f5870b0c93ca8918fa9b_128'}}",
                                placeholder: (context, url) => CircularProgressIndicator(),
                                // errorWidget: (context, url, error) => Icon(Icons.error),
                              ),
                            ),
                        // CircleAvatar(
                        //   backgroundImage: NetworkImage(
                        //       '${Address.homeHost}${controller.model?.data!.image_128}'
                        //   ),
                        //   // child: ExtendedImage.network('${Address.homeHost}${controller.model?.data?.image_128}'),
                        // ),
                        SizedBox(width: 5,),
                        Text('${controller.model?.data?.name}'),
                      ],
                    ),
                    Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
                  ],
                ),
              ),
              onTap: (){
                controller.selectImages();
              },
            ):GestureDetector(
              child: Container(
                padding:const EdgeInsets.only(left: 20,right: 15),
                alignment: Alignment.centerLeft,

                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('${list[index]}',style: appThemeData.textTheme.bodyText1,),
                    Row(
                      children: [
                       index ==1?Text('${controller.model?.data?.aliasName}'):
                      index==2?Text('${controller.model?.data?.sex}'):
                      index==3?Container(
                        alignment: Alignment.centerRight,
                        width: Get.width-130,
                        // color: Colors.yellow,
                        child: Text('${controller.model?.data?.contactAddress}',maxLines: 1,),
                      ):
                      index==4?Text('${controller.model?.data?.birthDay}'):
                      Container(),
                       Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,),
                     ],
                   )

                  ],
                ),
                color: Colors.white,
                margin: EdgeInsets.only(top: 2),
                height: 50,
              ),
              onTap: ()async{
                if(index==1){
                 var data = await Get.to(UserInfoUpDataView('修改昵称',
                   controllerText: controller.model?.data?.aliasName,));
                 if(data =='refresh'){
                   controller.requestDataWithUserInfo();
                 }
                }
                if(index ==2){
                  Get.bottomSheet(Container(
                    height: 100,
                    color: Colors.white,
                    child: Column(
                      children: [
                        GestureDetector(
                          child: MaterialButton(onPressed: () {
                            controller.
                            requestDataWithUpdataInfo(
                                sex: '男');
                            Get.back();
                          },child: Text('男'),),
                        ),
                        GestureDetector(
                          child: MaterialButton(onPressed: () {
                            controller.
                            requestDataWithUpdataInfo(
                                sex: '女');
                            Get.back();
                          },child: Text('女'),),
                        ),
                      ],
                    ),
                  ));
                }
                if(index == 3){
                  Get.to(UserInfoUpDataView('修改地址',controllerText: controller.model?.data?.contactAddress,),);
                }
                if(index ==4){

                  DatePicker.showDatePicker(context,
                      showTitleActions: true,
                      minTime: DateTime(1990, 1, 1),
                      maxTime: DateTime(2025, 12, 12), onChanged: (date) {

                      }, onConfirm: (date) {
                        var timeFormat = DateFormat("yyyy-MM-dd");
                        // DateTime dateTime= DateTime.now();
                        String timetest = timeFormat.format(date);
                        // print('time ===== ${dateTime.hour}:${dateTime.minute}');
                        controller.
                        requestDataWithUpdataInfo(birthday: '${timetest}');
                        // print('confirm $date');
                      }, currentTime: DateTime.now(), locale: LocaleType.zh);
                }
              },
            );
          },itemCount: list.length,
          // children: [
          //   Container(
          //     padding: EdgeInsets.only(left: 15,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Row(
          //           children: [
          //             CircleAvatar(),
          //             SizedBox(width: 5,),
          //             Text('${controller.model?.data?.name}'),
          //           ],
          //         ),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 80,
          //   ),
          //   SizedBox(height: 1,),
          //   Container(
          //     padding: EdgeInsets.only(left: 20,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Text('昵称',style: appThemeData.textTheme.bodyText1,),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 50,
          //   ),
          //   SizedBox(height: 1,),
          //   Container(
          //     padding: EdgeInsets.only(left: 20,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Text('微信',style: appThemeData.textTheme.bodyText1,),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 50,
          //   ),
          //   SizedBox(height: 1,),
          //   Container(
          //     padding: EdgeInsets.only(left: 20,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Text('QQ',style: appThemeData.textTheme.bodyText1,),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 50,
          //   ),
          //   SizedBox(height: 1,),
          //   Container(
          //     padding: EdgeInsets.only(left: 20,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Text('Email',style: appThemeData.textTheme.bodyText1,),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 50,
          //   ),
          //   SizedBox(height: 1,),
          //   Container(
          //     padding: EdgeInsets.only(left: 20,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Text('性别',style: appThemeData.textTheme.bodyText1,),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 50,
          //   ),
          //   SizedBox(height: 1,),
          //   Container(
          //     padding: EdgeInsets.only(left: 20,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Text('地址',style: appThemeData.textTheme.bodyText1,),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 50,
          //   ),
          //   SizedBox(height: 1,),
          //   Container(
          //     padding: EdgeInsets.only(left: 20,right: 15),
          //     alignment: Alignment.centerLeft,
          //     child: Row(
          //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
          //       children: [
          //         Text('生日',style: appThemeData.textTheme.bodyText1,),
          //         Icon(Icons.arrow_forward_ios,size: 15,color: Colors.grey,)
          //       ],
          //     ),
          //     color: Colors.white,
          //     height: 50,
          //   ),
          // ],
        );
      }),
    );
  }
}
